from rest_framework import serializers

from areas.models import Area


class AreasInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model=Area
        fields=['id','name']

class AreasCitySerializer(serializers.ModelSerializer):
    areas_set=AreasInfoSerializer(read_only=True,many=True)
    class Meta:
        model=Area
        fields=['id','name','areas_set']


# 视图集序列化器
class ProvinceSerializer(serializers.ModelSerializer):

    class Meta:
        model=Area
        fields=['id','name']


class SubsCitysSerializer(serializers.ModelSerializer):
    subs =ProvinceSerializer(many=True,read_only=True)
    class Meta:
        model=Area
        fields = ['subs','id','name']